package br.com.ccm.session.generic;

import java.util.Collection;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import br.com.ccm.dao.generic.GenericDao;
import br.com.ccm.exception.ValidationException;

@Stateless
public class GenericSession<T>{

	@EJB
	private GenericDao<T> dao;
	
	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public T salvar(T t) throws ValidationException {
		return dao.salvar(t);
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public T atualizar(T t) throws ValidationException{
		return dao.atualizar(t);
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
	public void excluir(T t) throws ValidationException{
		dao.excluir(t);		
	}

	public T findById(Class<?> clazz, Object id) {
		return dao.findById(clazz, id);
	}

	public Collection<T> findAll(Class<?> clazz) {
		return dao.findAll(clazz);
	}

}
